const Router = require('koa-router')

const GoodsRouter = new Router({ prefix: '/goods' })

const { upload, create, update, remove, restore,findAll } = require('../controllers/goods.controllers')

const { paramValidator } = require('../middleware/goods.middleware')

const { auth, hadAdminPermission } = require('../middleware/auth.middleware')

// 图片上传接口 
GoodsRouter.post('/upload', auth, hadAdminPermission, upload)
// 发布商品
GoodsRouter.post('/', auth, hadAdminPermission, paramValidator, create)
// 修改商品
GoodsRouter.put('/:id', auth, hadAdminPermission, paramValidator, update)
// 硬删除商品
GoodsRouter.delete('/:id', auth, hadAdminPermission, remove)
// 商品下架
GoodsRouter.post('/:id/off', auth, hadAdminPermission, remove)
// 商品上架
GoodsRouter.post('/:id/on', auth, hadAdminPermission, restore)
// 商品列表借口
GoodsRouter.get('/', findAll)

module.exports = GoodsRouter